<?php

namespace App\Models\Traits;


use DateTimeInterface;
use Illuminate\Database\Eloquent\Builder;

trait Commendable
{
    public static function bootCommendable()
    {
        //不需要全局查询用 withOutGlobalScope('is_delete')
        static::addGlobalScope('is_delete',function (Builder $builder){
            $builder->where('is_delete',0);
        });
    }
    //格式化时间
    public function serializeDate(DateTimeInterface $date)
    {
        return $date->format($this->dateFormat?:'Y-m-d H:i:s');
    }
}